package org.eudi.user.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eudi.user.dao.IUserDao;

import com.eudi.dubbo.common.User;

public class UserDaoImpl implements IUserDao{
	private static List<User> userList = new ArrayList<User>();
	private static Map<Integer, User> userMap = new HashMap<Integer, User>();

	static {
		List<User> users = new ArrayList<User>();
		User user1 = new User();
		user1.setId(1);
		user1.setName("张三");
		user1.setSex(1);
		user1.setAge(20);
		user1.setAddress("苏州");
		users.add(user1);
		User user2 = new User();
		user2.setId(2);
		user2.setName("李四");
		user2.setSex(2);
		user2.setAge(30);
		user2.setAddress("天津");
		users.add(user2);
		User user3 = new User();
		user3.setId(3);
		user3.setName("王五");
		user3.setSex(1);
		user3.setAge(40);
		user3.setAddress("邢台");
		users.add(user3);
	}
	
	/**
	 * @param user
	 */
	public void add(User user) {
		userList.add(user);
		userMap.put(user.getId(), user);
	}
	
	/**
	 * @return
	 */
	public List<User> findList() {
		return userList;
	}
	
	/**
	 * @param id
	 * @return
	 */
	public User get(int id) {
		return userMap.get(id);
	}

	public List<User> findUsers() {
		return userList;
	}

	public void remove(Integer id) {
		User u = userMap.get(id);
		userList.remove(u);
		userMap.remove(id);
	}
}
